﻿using System.Collections.Generic;
using Yun.Interface;
using Yun.Response;
using Yun.Util;

namespace Yun.Pay.Request
{
    /// <summary>
    /// 申请提现
    /// chenggou.pay.withdrawals.apply
    /// </summary>
    public class ApplyWithdrawalsRequest : ITopRequest<IntResultResponse>
    {
        /// <summary>
        /// 银行卡ID，提现至哪个银行卡
        /// </summary>
        public int BankCardId { get; set; }

        /// <summary>
        /// 提现的金额
        /// </summary>
        public double Money { get; set; }

        /// <summary>
        /// 支付密码
        /// </summary>
        public string PayPassword { get; set; }


        /// <summary>
        /// 自定义交易号，唯一，不可重复，不超过19位
        /// </summary>
        public string TradeNum { get; set; }

        /// <summary>
        /// IP地址
        /// </summary>
        public string Ip { get; set; }

        /// <summary>
        /// APP密匙
        /// 不要写在文档上
        /// </summary>
        public string AppSecret { get; set; }

        /// <summary>
        /// 支付单附加数据，在查询API和支付通知中原样返回，可作为自定义参数使用。
        /// </summary>
        public string PaymentAttach { get; set; }

        public string GetApiName()
        {
            return "chenggou.pay.withdrawals.apply";
        }

        public IDictionary<string, string> GetParameters()
        {
            var parameters = new YunDictionary
            {
                {"bankcardid", BankCardId},
                {"money", Money},
                {"paypassword", string.IsNullOrWhiteSpace(PayPassword)
                    ? ""
                    : (PayPassword.Length == 32 ? PayPassword : TopUtils.EncryptAes(PayPassword, AppSecret))},
                {"tradenum",TradeNum },
                {"ip",Ip },
                {"paymentattach",PaymentAttach }
            };

            return parameters;
        }

        public void Validate()
        {
            RequestValidator.ValidateRequired("money", Money);
            RequestValidator.ValidateMinValue("money", Money, 0.01);
            RequestValidator.ValidateRequired("bankcardid", BankCardId);
            RequestValidator.ValidateMinValue("bankcardid", BankCardId, 1);
        }
    }
}
